<template>
<view>
	<view class="d-kuan">
		<view class="d-waikuang-10">
			<view class="d-kuan d-yuanjiao-10">
				<view v-if="yonghuXinxi.openids" class="d-xia-10">
					<u-button type="info" :plain="true" @click="" class="d-xia-10">正在解绑小程序中</u-button>
				</view>
				<view v-else class="d-xia-10">
					<u-button type="info" :plain="true" @click="" class="d-xia-10">解绑成功</u-button>
				</view>
			</view>
		</view>
	</view>
	
	
</view>
</template>

<script>

var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
import config from "../../utils/config";
var pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
const app = getApp();
/*#ifdef APP-PLUS || H5*/
    var member = uni.getStorageSync('member');
/*#endif*/
/*#ifdef MP-WEIXIN*/
    var member = uni.getStorageSync('member');
/*#endif*/

export default {
  data() {
    return {
      isArticlesList: true,
      listStyle: config.getListStyle,
      shareTitle: config.getWebsiteName,
      pageTitle: '解绑小程序',
      articlesList: [],
	  yonghuXinxi: [],
      postype: "post",
      webSiteName: webSiteName,
      domain: domain,
	  member: [],
	  show: false
    };
  },
  computed: {
  	
  },
  watch: {
      yonghuXinxi(newVal, oldVal) {
        // 当message属性发生变化时，执行刷新操作
        //uni.reLaunch({ url: '/pages/wo/bangdingyicun' });
      }
    },
  components: {},
  props: {},
  
  onShow: function () {
	  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.getYonghuXinxi();
	console.log(member);
	//判断用户是否登录
	var userInfo = uni.getStorageSync('userInfo');
	if (userInfo) {
		// 保留二次开发
	} else {
		//否则跳转到登录页面
		uni.reLaunch({ url: '/pages/login/login'}) // 跳转到首页
	}
	
    var postype = 'post';

    if (options.postype) {
      postype = options.postype;
    }

    this.setData({
      postype: postype
    });
  },
  onReady: function () {
    uni.setNavigationBarTitle({
      title: this.pageTitle
    });
  },
  
  methods: {

    formSubmit: function (e) {
      var url = '../list/list';
      var key = '';

      if (e.currentTarget.id == "search-input") {
        key = e.detail.value;
      } else {
        key = e.detail.value.input;
      }

      if (key != '') {
        url = url + '?search=' + key;
        uni.navigateTo({
          url: url
        });
      } else {
        uni.showModal({
          title: '提示',
          content: '请输入内容',
          showCancel: false
        });
      }
    },

    async BangdingYicun() {
    	try {
    		uni.login({
    		    success: function (res) {
    		        console.log(res);
    		        if (res.code) {
    		            uni.getUserInfo({
    		                success: function (userRes) {
								//var that = this;
								var self = this; 
    		                    //发起网络请求D
    		                    uni.request({
    		                        url: Api.getWwwUrl()+"s=weixin&c=member&m=xcx_bangyicun",
    		                        data: {
    		                            json: userRes.rawData,
    		                            js_code: res.code,
										uid: member.uid,
										jiebang:1,
    		                        },
    		                        method: 'post',
    		                        header: {
    		                            'Content-Type': 'application/x-www-form-urlencoded',
    		                        },
    		                        success: function (res) {
    		                            uni.showToast({
    		                                title: "解绑成功",
    		                                icon: 'success',
    		                            });
										//self.getYonghuXinxi();
										//uni.navigateBack();
										setTimeout(() => {
										    uni.navigateBack({delta: 1});
										}, 1000); // 设置2秒后执行返回操作
										
    		                        }
									
    		                    });
								
    		                }
							
    		            });
						
    		        } else {

    		        }

    		    },

    		});
    		
    	} catch (error) {
    			console.error(error);
    			uni.showToast({
    				icon: 'none',
    				title: '登录失败，请稍后重试'
    			});
    		}
    },
	//会员信息
	getYonghuXinxi() {
			var self = this; 
			self.setData({
			  yonghuXinxi: []
			});
			var getYonghuXinxiRequest = wxRequest.getRequest(Api.getYonghuXinxi(member.id));
			getYonghuXinxiRequest.then(response => {
				if (response.data.code == 1) {
				  console.log(response.data.data); 
				  self.yonghuXinxi = response.data.data
				  //self.getYonghuXinxi();
				  if(response.data.data.openids) {
					  //二次开发
					  self.BangdingYicun();
				  } else {
					  
				  }
				  
				}
			});
		}
    },
	
};
</script>
<style>
@import "./wo.css";
page {
	background-color: #f3f4f7;
}
</style>